package com.eonmind.pay.controller;

import com.eonmind.common.contract.data.response.ResponseEntity;
import com.eonmind.common.provider.entity.pay.Order;
import com.eonmind.common.provider.entity.vip.VipPackage;
import com.eonmind.common.security.annotations.UserInfo;
import com.eonmind.pay.dto.OrderDto;
import com.eonmind.pay.service.OrderService;
import com.eonmind.user.contract.dto.UserInfoData;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName OrderController
 * @Description TODO
 * Author 32004
 * Date 2025/5/31 16:13
 * Version 1.0
 **/

@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {

    @Resource
    private OrderService orderService;

    /**
     * 分页查询订单信息
     *
     * @param pageRequest
     * @return
     * @ignoreParams userInfoData
     */
    @PostMapping("/page")
    @UserInfo
    public ResponseEntity<OrderDto> page(UserInfoData userInfoData, @RequestBody OrderDto.OrderPageRequest pageRequest){
        return orderService.pageOrder(userInfoData.getId(), pageRequest);
    }


    /**
     * 待支付订单信息查询
     *
     * @param id
     * @return
     * @ignoreParams userInfoData
     */
    @GetMapping("/id/{id}")
    public ResponseEntity<OrderDto.OrderResDto> getVipById(@PathVariable("id") Long id){
        return orderService.getOrderById(id);
    }

    /**
     * 获取最近订单信息
     *
     * @return
     * @ignoreParams userInfoData
     */
    @UserInfo
    @GetMapping("/recent")
    public ResponseEntity<List<OrderDto.OrderResDto>> getRecentOrder(UserInfoData userInfoData){
        return orderService.getRecentOrder(userInfoData.getId());
    }


    /**
     * 删除订单功能
     *
     * @param order
     * @return
     * @ignoreParams userInfoData
     */
    @PostMapping("/delete")
    public ResponseEntity<Boolean> deleteOrder(@RequestBody Order order){
        return orderService.deleteOrder(order);
    }



}
